<template>
  <el-select v-model="selectValue" :disabled="disabled" :readonly="readonly" @change="onChange">
    <el-option v-for="item in list" :key="item.id" :label="item.dictLabel" :value="item.dictValue" />
  </el-select>
</template>
<script setup>
import { postRequest, getLocalStorage } from "@/api/mains";
const props = defineProps({
  modelValue: {
    type: [Number, String],
    default: ""
  },
  params: {
    type: Object,
    default: () => {
      return {};
    }
  },
  disabled: {
    type: Boolean,
    default: false
  },
  readonly: {
    type: Boolean,
    default: false
  }
});

const emits = defineEmits(["update:model-value"]);

const selectValue = ref(props.modelValue);
const list = ref([]);

const getList = async () => {
  const { params } = props;
  const { url, enumCode } = params;

  //  若传入url则按通过url获取数据
  if (url) {
    const { datas } = await postRequest(props.url);
    list.value = datas;
  } else if (enumCode) {
    list.value = getLocalStorage()[enumCode];
  }

  console.warn(233, url, enumCode, list.value);
};

getList();

const onChange = value => {
  emits("update:model-value", value);
};
</script>
<style lang="scss"></style>
